<template>
  <div class="main">
    <el-drawer
      :modal-append-to-body="false"
      :append-to-body="true"
      title="发货信息"
      size="50%"
      :with-header="false"
      :visible.sync="detaildialog"
      :show-close="true"
      @close="addressClose"
    >
      <div style="position: relative">
        <div class="drawerTitle">
          <span>发货信息</span>
          <div class="close" @click="addressClose">
            <i class="el-icon-close" style="font-size: 24px;" />
          </div>
        </div>
      </div>
      <div class="elivery-list">
        <div v-for="(item,index) in multipleSelection" :key="index" class="list-item">
          <div class="left">
            <div class="left-icon">
              <i class="el-icon-shopping-bag-1" />
            </div>
            <div class="list-center">
              <div>订单状态: <span style="color: #bd312b;font-weight: bold">待发货</span> </div>
              <div>订单编号: <span style="font-weight: bold">{{ item.order_trade_no }}</span> </div>
            </div>
          </div>
          <div class="el-icon-close" @click="doClone(item)" />
        </div>
      </div>
      <div class="elivery-form">
        <div class="total">共<span>{{multipleSelection.length}}</span>条待发货数据</div>
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="发货类型" prop="status">
            <el-input v-model="ruleForm.status" disabled class="input-widht" />
          </el-form-item>
          <el-form-item label="快递公司" prop="express_name">
            <el-input v-model="ruleForm.express_name" placeholder="请输入快递公司" class="input-widht" />
          </el-form-item>
          <el-form-item label="快递单号" prop="express_num">
            <el-input v-model="ruleForm.express_num" placeholder="请输入快递单号" class="input-widht" />
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="ruleForm.remark" placeholder="请输入备注" type="textarea" :rows="2" class="input-widht" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="margin: 30px 0 0 90px;width: 120px;" @click="doSend">立即创建</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import { supplyCombinedDelivery } from '@/api/order/index'
export default {
  props: {
    multipleSelection: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      detaildialog: false,
      total: 0,
      ruleForm: {
        status: '待发货',
        express_name: '', // 快递
        express_num: '', // 快递单号
        remark: '', // 备注
        detail_ids: []
      },
      rules: {
        status: [
          { required: true, message: '请输入发货类型', trigger: 'blur' }
        ],
        express_name: [
          { required: true, message: '请输入快递公司', trigger: 'blur' }
        ],
        express_num: [
          { required: true, message: '请输入快递单号', trigger: 'blur' }
        ],
        remark: [
          { required: true, message: '请输入备注', trigger: 'blur' }
        ]
      }

    }
  },
  created() {
  },
  methods: {
    open() {
      this.detaildialog = true
      this.ruleForm = {}
      this.ruleForm.status = '待发货'
      this.$refs.ruleForm && this.$refs.ruleForm.clearValidate()
    },
    addressClose() {
      this.detaildialog = false
      this.$refs.ruleForm && this.$refs.ruleForm.clearValidate()
    },
    doClone(item) {
      if (this.multipleSelection.length <= 1) {
        return this.$messages.error('订单必须要有一条')
      }
      this.$emit('doClone', item)
    },
    doSend() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.ruleForm.detail_ids = []
          this.multipleSelection.forEach(item => {
            this.ruleForm.detail_ids.push(item.detail_id)
          })
          supplyCombinedDelivery(this.ruleForm).then(res => {
            if (res.code === 200) {
              this.ruleForm = {}
              this.ruleForm.status = '待发货'
              this.$messages.success('创建成功')
              this.detaildialog = false
              this.$emit('getListWay')
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    batchSend() {
      // supplyOrderImport  批量发送接口
    }
  }

}
</script>
<style scoped lang="scss">
.main{
  position: relative;

}
//去掉滚动条
//.elivery-list::-webkit-scrollbar {
//  display: none
//}
.elivery-list{
  width: 96%;
  padding: 20px 20px 20px 30px;
  max-height: 450px;
  overflow-y: scroll;
  .list-item{
    height: 55px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    .left{
      display: flex;
      align-items: center;
      .left-icon{
        position: relative;
        width: 50px;
        height: 55px;
        margin-right: 10px;
        background-color: #1890ff;
        border-radius: 10px;
        .el-icon-shopping-bag-1{
          position: absolute;
          top: 50%;
          left: 50%;
          color: #FFFFFF;
          font-size:30px;
          transform: translate(-50%,-50%);
        }
      }
      .list-center{
      font-size: 14px;
      color: #303030;
      }
    }
    .el-icon-close{
      font-size: 24px;
      color: rgb(45, 58, 75);
      cursor: pointer;
    }
  }
}
.elivery-form{
  margin: 10px 0 0 30px;
  .total{
    color: #383838;
    font-size: 14px;
    line-height: 50px;
    font-weight: 550;
    span{
      color: #0076f6;
      font-weight: 550;
    }
  }
}
.input-widht{
  width: 300px;
}
</style>
